import axios from 'axios'
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';


axios.defaults.baseURL = 'http://ay8wdheq.dongtaiyuming.net/'

// axios.defaults.headers.post['Content-Type'] = 'application/json;charset=utf-8'

// 添加请求拦截器

let AUTH_TOKEN = window.localStorage.getItem('myToken') || ''

axios.interceptors.request.use(function (config) {

  // 在发送请求之前在请求头配置token
  config.headers['token'] = AUTH_TOKEN;

  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error)
})

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  return response.data
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error)
})



// 登录
const getLogin = params => axios.post('login', params)

// 分支企业动态数据请求
const getBranchDynamics = params => axios.get('BranchEnterprises', { params })

// 通过 全部通过
const getUpdateStatusPass = params => axios.post('updateStatusPass', params)
// 驳回 全部驳回
const getUpdateStatusTurn = params => axios.post('updateStatusTurn', params)

// 上传图片
const getFile = params => axios.post('banner/upload', params)

// 分公司状态查找
const getEnterpriseName = params => axios.post(`status/${params.status}`)

// 分支企业搜索
const getBranchCompanys = params => axios.get('selectAll', { params })

// 新增企业动态
const getInsertEnterprise = params => axios.post('insertEnterprise', params)

// 查询全部分支企业
const getSelectBranchCompanyAll = params => axios.get('selectBranchCompanyAll', params)

// 删除企业动态
const getDeleteEnterprise = id => axios.delete(`deleteEnterprise/${id}`)

// 查询单个用户
const getSelectOnly = params => axios.get('selectOnly', { params })

// 编辑企业动态
const getUpdateEnterprise = params => axios.post('updateEnterprise', params)

//获取banner
const getBanner = params => axios.get('banner/page', { params })
//修改banner
const editBanner = params => axios.put('banner', params)
//banner图片上传
const bannerUpload = params => axios.post('banner/upload', params, { headers: { "Content-Type": " multipart/form-data" } })
//添加banner
const addBanner = params => axios.post('banner', params)
//删除图片
const delImg = params => axios.delete(`banner/remove?path=${params}`)
//删除banner
const delBanner = params => axios.delete(`banner/${params.bannerId}`)
//获取新闻
const getNews = params => axios.get('news/getNews', { params })
//修改新闻
const editNews = params => axios.put('news/updateNews', params)
//添加新闻
const addNews = params => axios.post('news/addNews', params)
//删除新闻
const delNews = params => axios.delete(`news/deleteNews/${params.newsId}`)
//批量发布
const batchRelease = release => axios.post(`news/batchRelease`, release)

// 删除单个合作伙伴
const getDeletePartner = (cooperativeId) => axios.delete(`partner/deletePartner/${cooperativeId}`)
// 删除行业
const getDeleteIndustry = (id) => axios.delete(`industryManagement/${id}`)
// 查询 
const getSelectAllIndustry = params => axios.get('partner/selectAllIndustry')

// 获取行业管理
const getIndustryManagement = params => axios.get('industryManagement', { params })
//行业管理添加
const getAddIndustry = params => axios.post('industryManagement', params)
// 添加合作伙伴
const getAddPartner = params => axios.post('partner/addPartner', params)
// 根据ID获取合作伙伴
const getCooperativeDetails = params => axios.get(`partner/selectPartnerById/${params}`)
// 编辑合作伙伴
const getEditCooperative = params => axios.put(`partner/updatePartner`, params)
//排序
const getUpdateSort = ({ cooperativeId, chooseSort }) => axios.get(`partner/updateSort/${cooperativeId}/${chooseSort}`)
//编辑行业
const getEditIndustry = params => axios.put('industryManagement', params)
// 获取合作伙伴数据列表
const getPartner = params => axios.get('partner/getPartners', { params })

// 初始化分公司管理列表
const getBranchCompany = params => axios.get('BranchCompany', { params })
// 添加分公司
const getAddBranchCompany = params => axios.post('BranchCompany', params)
// 删除分公司
const getDeleteBranchCompany = params => axios.delete(`BranchCompany/${params.id}`)
// 编辑分公司
const getEditBranchCompany = params => axios.put(`BranchCompany`, params)
// 分公司排序
const getModifyBranch = params => axios.put(`BranchCompanySort/${params.branchId}/${params.sort}`)

// 初始化媒体查询
const getMedia = params => axios.get('MediaCoverage', { params })

// 添加分公司
const getAddMedia = params => axios.post('MediaCoverage', params)
// 删除分公司
const getDeleteMedia = params => axios.delete(`MediaCoverageDelete/${params.mediaId}`)
// 编辑分公司
const getEditMedia = params => axios.put(`MediaCoverageUpdate`, params)
// 分公司排序
const getModifyMedia = params => axios.put(`MediaCoverageSort/${params.mediaId}/${params.mediaSort}`)



// 栏目页面初始化
const getColumn = params => axios.get("http://192.168.1.121:8080/columnManagements")

// 获取网页当前信息
const getWebInformation = params => axios.get("http://192.168.1.121:8080/details/select")
// 修改网页信息
const getWebOperate = params => axios.post("http://192.168.1.121:8080/details/operate", params)

// 保存排序
const getModify = params => axios.put(`http://192.168.1.121:8080/updateColumnSort`, { params })

// 删除栏目
const getDeleteColumn = params => axios.delete(`http://192.168.1.121:8080/columnManagement/${params}`)

// 获取一级栏目
const getFatherColumn = params => axios.get("http://192.168.1.121:8080/allFatherColumnManagement")

// 根据Id获取栏目信息
const getColumnById = params => axios.get(`http://192.168.1.121:8080/ColumnManagement/${params}`)

// 设置栏目
const getUpdateColumn = params => axios.put(`http://192.168.1.121:8080/columnManagements`, params)

// 设置栏目内容
const getContent = ({ columnId, content }) => axios.put(`http://192.168.1.121:8080/content?columnId=${columnId}&content=${content}`)
// 添加栏目
const getAddColumn = params => axios.put("http://192.168.1.121:8080/insertColumnManagement", params)

// 业务领域请求信息
const getbusiness1 = (params) => axios.get('http://192.168.1.121:8080/business/select')
// 业务领域保存信息
const getbusiness = (params) => axios.post('http://192.168.1.121:8080/business/add', params)
// 用户页面请求信息
const getuser = (params) => axios.get(`http://192.168.1.121:8080/users/baseKey?baseKey=${params.baseKey}&size=${params.size}&page=${params.page}`)
// 添加用户信息
const addUser = (params) => axios.post('http://192.168.1.121:8080/add', params, { headers: { 'Content-Type': 'application/json;charset=utf-8' } })
// 添加用户 选择公司
const selectCompany = (params) => axios.get('http://192.168.1.121:8080/details/companies')
// 删除用户信息
const deleteUser = (params) => axios.delete('http://192.168.1.121:8080/delete/' + params.userId)
// 重置密码
const resetPassword = (params) => axios.get('http://192.168.1.121:8080/resetPassword?userId=' + params.userId)
// 编辑用户
const editUsers = (params) => axios.post('http://192.168.1.121:8080/update', params, { headers: { 'Content-Type': 'application/json;charset=utf-8' } })



export default {
  getBanner,
  editBanner,
  bannerUpload,
  addBanner,
  delImg,
  delBanner,
  getNews,
  editNews,
  addNews,
  delNews,
  batchRelease,
  getColumn,
  getWebInformation,
  getWebOperate,
  getModify,
  getDeleteColumn,
  getColumnById,
  getFatherColumn,
  getUpdateColumn,
  getContent,
  getAddColumn,
  getPartner,
  getDeletePartner,
  getIndustryManagement,
  getSelectAllIndustry,
  getAddPartner,
  getDeleteIndustry,
  getCooperativeDetails,
  getEditCooperative,
  getUpdateSort,
  getAddIndustry,
  getEditIndustry,
  getBranchCompany,
  getAddBranchCompany,
  getDeleteBranchCompany,
  getEditBranchCompany,
  getModifyBranch,
  getMedia,
  getAddMedia,
  getDeleteMedia,
  getEditMedia,
  getModifyMedia,
  getbusiness,
  getbusiness1,
  getuser,
  addUser,
  deleteUser,
  resetPassword,
  editUsers,
  selectCompany,
  getLogin,
  getBranchDynamics,
  getEnterpriseName,
  getBranchCompanys,
  getInsertEnterprise,
  getDeleteEnterprise,
  getSelectOnly,
  getUpdateEnterprise,
  getSelectBranchCompanyAll,
  getUpdateStatusPass,
  getUpdateStatusTurn,
  getFile
}

